package net.trustie.model;

import net.trustie.utils.DateHandler;
import net.trustie.utils.StringHandler;
import core.AfterExtractor;
import core.Page;
import core.ValidateExtractor;
import us.codecraft.webmagic.model.annotation.ExtractBy;
public class java_forge_Model implements AfterExtractor, ValidateExtractor {

	private int project_id = 0;
    private String project_url = "";
    @ExtractBy("//*[@id='pagecontent']/span/table/tbody/tr/td[1]/div[1]/div/h4/a/text()")
	private String project_name = "";
    @ExtractBy("//*[@id='pagecontent']/span/table/tbody/tr/td[1]/div[1]/div/table/tbody/tr/td/a[2]/text()")
	private String project_author = "";
    @ExtractBy("//*[@id='pagecontent']/span/table/tbody/tr/td[1]/div[1]/div/table/tbody/tr/td/span/text()")
	private String project_created_time="";
	private String extractTime = "";
    private int history = 0;
	
	@Override
	public void validate(Page page) {
		// TODO Auto-generated method stub
		//处理项目url
		this.project_url= page.getPageUrl();
		//处理项目Id
		this.project_id=(Integer.parseInt(project_url.substring(project_url
				.lastIndexOf("/") + 1)));
		//处理项目创建时间
		this.project_created_time = DateHandler.standardForDate(project_created_time);
		//处理抽取时间
		this.extractTime = DateHandler.getExtractTime();	
	}

	@Override
	public void afterProcess(Page page) {
		// TODO Auto-generated method stub
		if (StringHandler.isAtLeastOneBlank(this.project_name, this.project_author,
				this.project_url)) {
			page.setResultSkip(this, true);
			return;
		}		
		if (!DateHandler.canFormatToDate(this.project_created_time, this.extractTime)) {
			page.setResultSkip(this, true);
			return;
		}	
	}

	public int getProject_id() {
		return project_id;
	}

	public void setProject_id(int project_id) {
		this.project_id = project_id;
	}

	public String getProject_url() {
		return project_url;
	}

	public void setProject_url(String project_url) {
		this.project_url = project_url;
	}

	public String getProject_name() {
		return project_name;
	}

	public void setProject_name(String project_name) {
		this.project_name = project_name;
	}

	public String getProject_author() {
		return project_author;
	}

	public void setProject_author(String project_author) {
		this.project_author = project_author;
	}

	public String getProject_created_time() {
		return project_created_time;
	}

	public void setProject_created_time(String project_created_time) {
		this.project_created_time = project_created_time;
	}

	public String getExtractTime() {
		return extractTime;
	}

	public void setExtractTime(String extractTime) {
		this.extractTime = extractTime;
	}

	public int getHistory() {
		return history;
	}

	public void setHistory(int history) {
		this.history = history;
	}
	 
}
